import axios from 'axios';
import { ElMessage } from 'element-plus';

const request = axios.create({
  baseURL: process.env.VUE_APP_BASE_URL,
});

// 添加响应拦截器
request.interceptors.response.use(
  (response) => {
    if (response) {
      // console.log(response);
    }

    return response;
  },
  (error) => {
    if (error.response.status === 400) {
      ElMessage.error(error.response.data.message || '网络错误');
    }

    if (error.response.status === 401) {
      ElMessage.error(error.response.data.message || '权限错误');
    }

    if (error.response.status === 500) {
      ElMessage.error(error.response.data.message || '服务器错误');
    }

    return Promise.reject(error);
  },
);

export default request;
